package com.hackerrank.contests.nov13.challenges.poweroflargenumbers;

import java.math.BigInteger;
import java.util.Scanner;

public class Solution {
	private static final long MODULUS = 1000000007;
	public static long pow(long base, BigInteger exponent, long modulus) {
	    long result = 1;
	    while (exponent.compareTo(BigInteger.ZERO) > 0) {
	       if (exponent.testBit(0))
	           result = (result * base) % modulus;
	       base = (base * base) % modulus;
	       exponent = exponent.shiftRight(1);
	    }
	    return result;
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = in.nextInt();
		for(int t = 0; t < T; t++) {
			BigInteger A = in.nextBigInteger(), B = in.nextBigInteger();
			System.out.println(pow(A.remainder(new BigInteger(Long.toString(MODULUS))).longValue(), B, MODULUS));
		}
	}
}
